<template>
  <div class="app-container">
    <section>
      <div class="contentBox">
        <div class="content">
          <el-form
            ref="form"
            :model="form"
            :rules="rules"
            class="form"
            label-width="110px"
          >
            <el-form-item label="公司名称" style="width: 100%" prop="name">
              <el-input style="width: 250px" v-model="form.name" :readonly="type == 3"></el-input>
            </el-form-item>
            <el-form-item label="税率" style="width: 100%" prop="tax_rate">
              <el-input style="width: 250px" v-model="form.tax_rate" :readonly="type == 3"></el-input>
            </el-form-item>
            <el-form-item
              label="纳税人识别号"
              style="width: 100%"
              prop="identification"
            >
              <el-input
              :readonly="type == 3"
                style="width: 250px"
                v-model="form.identification"
              ></el-input>
            </el-form-item>
            <el-form-item label="地址" style="width: 100%" prop="address">
              <el-input style="width: 250px" v-model="form.address" :readonly="type == 3"></el-input>
            </el-form-item>
            <el-form-item label="电话" style="width: 100%" prop="phone">
              <el-input style="width: 250px" v-model="form.phone" :readonly="type == 3"></el-input>
            </el-form-item>
            <el-form-item
              label="开户行名称"
              style="width: 100%"
              prop="bank_name"
            >
              <el-input
                style="width: 250px"
                v-model="form.bank_name"
                :readonly="type == 3"
              ></el-input>
            </el-form-item>
            <el-form-item
              label="开户行账号"
              style="width: 100%"
              prop="bank_account"
            >
              <el-input
              :readonly="type == 3"
                style="width: 250px"
                v-model="form.bank_account"
              ></el-input>
            </el-form-item>
          </el-form>
          <div style="margin-top: 40px">
            <el-button style="width: 110px" @click="$router.go(-1)"
              >取消</el-button
            >
            <el-button
              v-if="type != 3"
              type="primary"
              style="width: 110px"
              @click="save"
              >确定</el-button
            >
          </div>
        </div>
      </div>
    </section>
  </div>
</template>
<script>
export default {
  data() {
    return {
      type: "",
      coupon_no: "",
      times: "",
      value1: false,
      editor: "",
      form: {
        id: "",
        name: "",
        identification: "",
        tax_rate: "",
        address: "",
        phone: "",
        bank_name: "",
        bank_account: "",
      },
      store_ids: [],
      rules: {
        name: [
          { required: true, message: "请输入开票公司名称", trigger: "blur" },
        ],
        identification: [
          { required: true, message: "请输入纳税人识别号", trigger: "blur" },
        ],
        tax_rate: [{ required: true, message: "请输入税率", trigger: "blur" }],
        address: [
          { required: true, message: "请输入公司地址", trigger: "blur" },
        ],
        phone: [{ required: true, message: "请输入公司电话", trigger: "blur" }],
        bank_name: [
          { required: true, message: "请输入开户行名称", trigger: "blur" },
        ],
        bank_account: [
          { required: true, message: "请输入开户行账号", trigger: "blur" },
        ],
      },
      roleList: [],
      list: [],
    };
  },
  created() {
    if (this.$route.query.id) {
      this.form.id = this.$route.query.id;
      this.getDetails();
    }
    if (this.$route.query.type) {
      this.type = this.$route.query.type;
    }
  },
  mounted() {},
  methods: {
    // 获取详情
    async getDetails() {
      let { code, data } = await this.$Http.getCompany({ id: this.form.id });
      if (code) {
        this.form = {
          id: data.id,
          name: data.name,
          identification: data.identification,
          tax_rate: data.tax_rate,
          address: data.address,
          phone: data.phone,
          bank_name: data.bank_name,
          bank_account: data.bank_account,
        };
      }
    },
    // 新增优惠券
    save() {
      this.$refs.form.validate(async (valid) => {
        if (valid) {
          let { code, data } = await this.$Http.setCompany(this.form);
          if (code) {
            if (this.form.id) {
              this.$message.success("编辑成功");
            } else {
              this.$message.success("添加成功");
            }
            this.$router.go(-1);
          }
        } else {
          return false;
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.app-container {
  section {
    .contentBox {
      background: #fff;
      border-radius: 8px;
      padding: 0px 24px 20px;
      min-width: 700px;
      padding-top: 30px;
      min-height: calc(100vh - 165px);
      .title {
        line-height: 70px;
        font-size: 18px;
        font-weight: 600;
        color: #383b40;
        .el-icon-close {
          cursor: pointer;
        }
      }
    }
    .content {
      max-width: 700px;
      height: 100%;
      .form {
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-start;
      }
    }
  }
}
.wrap {
  display: flex;
  p {
    margin-right: 20px;
    line-height: 35px;
    border-radius: 4px;
    background: #f1f1f1;
    font-size: 16px;
    padding: 0 20px;
  }
}
p {
  margin: 0;
}
.addTxt {
  color: #1890ff;
}
</style>